﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog ms-modal-dialog" style="width:800px; margin-top: 150px;">

  <div class="modal-content">

    <div class="modal-header">

      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <h4 class="modal-title"><i class="glyphicon glyphicon-fire" title="编辑模版"></i>&nbsp;&nbsp;<span>编辑模版</span></h4>
    </div>

    <form class="form-horizontal ms-form" method="POST" action="${ctx.host}/coupon-template/${couponTemplate.id}" data-validate="true">
      
      <input type="hidden" name="_method" value="PATCH">
      <input type="hidden" name="id" value="${couponTemplate.id }">
      
      <div class="modal-body">
        <div class="form-group ms-form-group">
          <label class="col-xs-2 control-label">优惠券名称</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="inputName" value="${couponTemplate.name}" data-validate="required" />
          </div>
          
          <label class="col-xs-2 control-label">折扣类型</label>
          <div class="pull-left" style="width: 30%">
            <select name="discountType" class="form-control select2 select-style" data-validate="required">
              <option value=""></option>
              <c:forEach var="couponTemplateDiscountType" items="${enums['couponTemplateDiscountType']}" >
                <option value="${couponTemplateDiscountType}" ${couponTemplate.discountType eq couponTemplateDiscountType ? 'selected' : ''}>${couponTemplateDiscountType.description}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group ms-form-group">
          <label class="col-xs-2 control-label">可转赠</label>
          <div class="pull-left" style="width: 30%">
            <select name="giveAvailable" class="form-control select2 select-style" data-validate="required">
              <option value=""></option>
              <option value="false" ${not couponTemplate.giveAvailable ? 'selected' : ''}>否</option>
              <option value="true" ${couponTemplate.giveAvailable ? 'selected' : ''}>是</option>
            </select>
          </div>
        </div>
        
        <div id="fixed_amount" class="form-group ms-form-group ${couponTemplate.discountType.isFixedAmount() ? '' : 'hide'}">
          <label class="col-xs-2 control-label">面值</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="inputAmount" value="${couponTemplate.amount/100}" data-validate="required|float" placeholder="请输入面值" />
          </div>
          
          <label class="col-xs-2 control-label">最低消费金额</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="inputMinAmount" value="${couponTemplate.minAmount / 100}" data-validate="required|float"  placeholder="请输入最低消费金额" />
          </div>
        </div>
    
      </div>

      <div class="modal-footer ms-modal-footer">
        <button type="submit" class="btn ms-btn btn-primary">确定</button>
        <button type="button" class="btn ms-btn ms-btn-gary" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>

  $(function() {
    $('select[name="discountType"]').select2({
        placeholder : '请选择所属折扣类型',
        minimumResultsForSearch : -1,
        allowClear : true
      });
    
    $('select[name="giveAvailable"]').select2({
        placeholder : '请选择是否可转赠',
        minimumResultsForSearch : -1,
        allowClear : false
      });
    
    $('select[name="type"]').select2({
      placeholder : '请选择所属类型',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    
    $('select[name="product"]').select2({
      placeholder : '请选择所属产品',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    

  })
</script>
